/*
 *  vcd2tab - Converter of VCD format in plain text tab separated.
 *  Copyright (C) 2011  Marco Giammarini
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Marco Giammarini 
 *  Via Arnaldo da Brescia, 7
 *  60019, Senigallia (AN), Italy
 *  http://www.warcomeb.it
 *  m.giammarini@warcomeb.it
 */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::cerr;

#include <fstream>
using std::ifstream;
using std::ofstream;


//@{
/** Project and authors information. */
#define AUTHORS_NAME            "Marco Giammarini"
#define AUTHORS_DOMAIN          "http://www.warcomeb.it"
#define AUTHORS_EMAIL           "m.giammarini@warcomeb.it"

#define PROJECT_NAME            "vcd2tab"
#define PROJECT_VERSION         "0.1.0"
#define PROJECT_YEAR_COPYRIGHT  "2011"
//@}

void
print_usage (void)
{
	cout << "Usage:\n"
			 << "  vcd2tab [options] -i <inputfile> -o <outputfile>\n\n"
			 << "Usage options:\n"
			 << "  -h               This menu\n"
			 << "  -v               Version and copyright informations\n"
			 << "  -i inputfile     The name of input file to covert\n"
			 << "  -o outputfile    The name of output file\n\n";
}

void
print_version (void)
{

}

int
main (int argc, char **argv)
{
	char * in_file_name = NULL;
	char * out_file_name = NULL;

	ifstream in_file;
	ofstream out_file;

	int c;

	if (argc == 1)
	{
		print_usage();
		return 1;
	}

	opterr = 0;

	while ((c = getopt (argc, argv, "hvi:o:")) != -1)
	{
		switch (c)
		{
		case 'h':
			print_usage();
			return 1;
		case 'v':
			print_version();
			return 1;
		case 'i':
			in_file_name = optarg;
			break;
		case 'o':
			out_file_name = optarg;
			break;
		case '?':
			if ((optopt == 'i') || (optopt == 'o'))
			{
				fprintf (stderr, "Option -%c requires an argument.\n", optopt);
			}
			else if (isprint (optopt))
			{
				fprintf (stderr, "Unknown option `-%c'.\n", optopt);
			}
			else
			{
				fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
			}
			return 1;
		default:
			abort ();
		}
	}

	/* Open input file. */
	if (in_file_name != NULL) 
	{
		in_file.open(in_file_name);
		if(!in_file.is_open())
		{
			cout << "Error: unable to open <" << in_file_name << "> file!" << endl;
			return 1;
		}
	}
	else
	{
		cout << "Error: the name of input file is modatory!" << endl;
		return 1;
	}

	/* Open output file. */
	if (out_file_name != NULL) 
	{
		out_file.open(out_file_name);
		if(!out_file.is_open())
		{
			cout << "Error: unable to open <" << out_file_name << "> file!" << endl;
			return 1;
		}
	}
	else
	{
		cout << "Error: the name of output file is modatory!" << endl;
		return 1;
	}

	return 0;
}
